'use strict';
module.exports = app => {
  const { STRING, INTEGER, TEXT } = app.Sequelize;
   const Chat = app.model.define(
      'Chat',
      {
          id: {type: INTEGER, primaryKey: true, autoIncrement: true},
          message: TEXT,
        friend_id: INTEGER,
        user_id: INTEGER,
      },
      {
          tableName: 'chat',
          timestamps: true, // 启用时间戳(createdAt, updatedAt)
          updatedAt: 'updated_time', // 不想要 updatedAt
          createdAt: 'create_time', // 想要  createdAt 但是希望名称叫做 created_at
      }
  );
    Chat.associate = function() {
        // 关联用户表
        app.model.Chat.belongsTo(app.model.User, { foreignKey: 'user_id', targetKey: 'id', as: 'user' });
        // 接收方用户
        app.model.Chat.belongsTo(app.model.User, { foreignKey: 'friend_id', targetKey: 'id', as: 'friend' });
    }
   return Chat
};
